#!/usr/bin/env python  3.872910e-04,1.708899e-01
# -*- coding: utf-8 -*  
   
import time  
import thread  
import threading
from time import sleep,ctime
import serial.tools.list_ports
import web  
import datetime
import myfont
urls = (  
    '/(.*)', 'hello'  
)  
  
app = web.application(urls, globals())  

class hello:  
    def GET(self, name):  
        date = datetime.datetime.now()
        i = web.input(times=1)  
        if not name:   
            qname = 'world'  
        #for c in xrange(int(i.times)):   
            #print 'Hello,', name+'!' 
        elif "inint" in name:
            qlist=name.split('_')
            qname=qlist[0]
            if qlist[2]=='0':
                text = u'第一行测试'  
                fr = myfont.FontRender('./HZK16/hzk16s')
                fr.convert_hex(text, ft=1, ff=0)  
            if qlist[2]=='1':
                text = u'第二行测试'  
                fr = myfont.FontRender('./HZK16/hzk16s')
                fr.convert_hex(text, ft=1, ff=0)  
            if qlist[2]=='2':
                text = u'第三行测试'  
                fr = myfont.FontRender('./HZK16/hzk16s')
                fr.convert_hex(text, ft=1, ff=0)  
            print fr.get_rect_hex()  
            return qname + str(fr.get_rect_hex()).replace(' ', '')
        elif "come" in name:
            WebThread.message=name+'_'+'isok'
            return 'isok' 
        else:
            WebThread.message=name
            qname = name
            return 'Hello,' + qname 

class WebThread(threading.Thread):
    message=''  
    def __init__(self,name = 'WebThread'):  #初始化线程        
        threading.Thread.__init__(self, name = name)
        self.__flag = threading.Event()     # 用于暂停线程的标识
        self.__flag.set()       # 设置为True
        self.__running = threading.Event()      # 用于停止线程的标识
        self.__running.set()      # 将running设置为True
    def run(self):        
        global flag_zhuan
        app.run() 
    def pause(self):
        print "暂停"
        self.__flag.clear()     # 设置为False, 让线程阻塞

    def resume(self):
        print "重启"
        self.__flag.set()    # 设置为True, 让线程停止阻塞
    #关闭串口线程
    def join(self, timeout = None):
        """ Stop the thread. """
        self.stopped = True
        self.__flag.set()       # 将线程从暂停状态恢复, 如何已经暂停的话
        self.__running.clear()        # 设置为False 
        print "COMThread.join()"
        threading.Thread.join(self, timeout)
if __name__=='__main__':  
    com_thread=WebThread()  
    com_thread.start()
    while True:  
        if com_thread.message!='':
            print com_thread.message
            com_thread.message=''
            print 'next line'  